<?php

/**
 * IndexController is the default controller for this application
 */
class IndexController extends ControllerBase {
	public function __construct() {
		parent::__construct ();
		
		// Set page name
		$this->setPageName ( 'dashboard' );
	}
	
	/**
	 * The "index" action is the default action for all controllers -- the
	 * landing page of the site.
	 *
	 * @return void
	 */
	public function indexAction() {
		$smarty = Zend_Registry::get ( 'smarty' );
		$dealsDataService =  new DealsDataService();
		//get Deals
		$arr = array('G.city_id' => 1);
		$where = " AND D.status > 0";
		$where .= " AND DATE_FORMAT(D.started_deal, '%Y-%m-%d %H:%i:%s') <= '".date('Y-m-d') . ' ' . date('H:i:s') ."'";
		$where .= " AND DATE_FORMAT(D.expired_deal, '%Y-%m-%d %H:%i:%s') >= '".date('Y-m-d') . ' ' . date('H:i:s')."'";

		$listDeals = $dealsDataService->getAllDeals ( $arr , 'rand()', null, null, $where );
		$this->smarty->assign('grouponEntity', new GrouponEntity());
		$smarty->assign('dealsList', $listDeals);
		$smarty->assign ( 'SMARTY_CONTENT_PATH', 'Admin/Index/index.tpl' );
		$smarty->display ( APPLICATION_PATH . '/Layouts/Admin/MainLayout.tpl' );
	}
	
	public function onlineusersAction() {
		$this->smarty->assign ( 'arrUserSessionEntity', $this->userSessionDataService->getUserOnline () );
		
		$this->smarty->assign ( 'isOnlineUserPage', 1 );
		$this->smarty->assign ( 'SMARTY_CONTENT_PATH', 'Admin/Index/onlineusers.tpl' );
		$this->smarty->display ( APPLICATION_PATH . '/Layouts/Admin/MainLayout.tpl' );
	}
	
	public function uservisithistoryAction() {
		$userId = $this->getQuery ( 'userId', '' );
		$sid = $this->getQuery ( 'sid', '' );
		$arrElement = array ();
		if (! empty ( $userId )) {
			$arrElement ['userId'] = $userId;
		}
		if (! empty ( $sid )) {
			$arrElement ['userSessionId'] = $sid;
		}
		$this->smarty->assign ( 'arrUserSessionVisitEntity', $this->userSessionVisitDataService->getItems ( $arrElement, 'user_session_visit.createdTime DESC', 0, 200 ) );
		
		$this->smarty->assign ( 'SMARTY_CONTENT_PATH', 'Admin/Index/user_visit_history.tpl' );
		$this->smarty->display ( APPLICATION_PATH . '/Layouts/Admin/MainLayout.tpl' );
	}
}
